import {ref, Ref} from "vue";

interface AlterReturn {
    alterMessage: Ref<string>
    alterActive: Ref<boolean>
    setAlter: (message: string) => void
}

export function useAlter(message: string, time = 1000): AlterReturn {
    const alterMessage = ref(message)
    const alterActive = ref(false)

    function setAlter(message: string) {
        alterMessage.value = message
        alterActive.value = true
        setTimeout(() => {
            alterActive.value = false
        }, time)
    }

    return {
        alterActive,
        alterMessage,
        setAlter
    }
}